package org.minbox.framework.command.execute.output;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * {@link Output} abstract implement
 *
 * @author 恒宇少年
 */
public abstract class AbstractOutput implements Output {
    /**
     * Format the input stream content as a string
     *
     * @param is {@link InputStream}
     * @return Input stream content
     */
    protected String getContent(InputStream is) {
        String content = null;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuilder sb = new StringBuilder();
            while ((line = br.readLine()) != null) {
                sb.append(line + "\n");
            }
            content = sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return content;
    }
}
